
#ifndef USER_H
#define USER_H

#include "led.h"
#include "AwesomeUsart.h"
#include "param.h"
#include "at_protocol.h"
#include "mavlink.h"

#define USART1_ENABLE   0
#define USART2_ENABLE   1
#define USART3_ENABLE		1

typedef enum AT_TYPE{
	AT_TYPE_NONE = 0,
	AT_TYPE_SERIAL1,
	AT_TYPE_SERIAL2,
	AT_TYPE_SERIAL3,
	AT_TYPE_MAIN_SERIAL,
}AT_TYPE;

typedef struct _cmera_config{
	uint8_t   open_close_level_in	:		1; 
	uint8_t 	open_level   				: 	1;
	uint8_t 	record_level  		  : 	1;
	uint8_t 	take_photo_level 		:   1;
	uint16_t 	open_time_ms 				:   16;
	uint16_t 	record_time_ms				:   16;
	uint16_t 	take_photo_time_ms	:   16;
}CameraConfig;

typedef struct _motor_config {
	uint16_t 	rc_min_pwm				:		16;
	uint16_t  rc_trim_pwm				:   16;
	uint16_t  rc_max_pwm				:   16;
	uint16_t  rc_error					:   16;
	uint16_t  open_pwm					:   16;
	uint16_t  close_pwm					:   16;
}MotorConfig;

#define MAX_RC_MAP_CHANNEL  16
typedef struct _rc_map {
	uint8_t camera_open_close_map;
	uint8_t camera_take_photo_map;
	uint8_t camera_record_map;
	uint8_t motor_map;
}RCMap;

/* event define */
#define 	CAMERA_OPEN_CLOSE_EVENT			((uint32_t)(1u<<0)) 
#define   CAMERA_TAKE_PHOTO_EVENT     ((uint32_t)(1u<<1))

void system_init(void);

void app(void);

void led_run(uint32_t time_ms);

void start_usart_rx(UART_HandleTypeDef *huart);
	
void usart_set_read_buff(UART_HandleTypeDef *huart, uint8_t data);

void mavlink_send(unsigned char* buff, uint32_t len);

extern mavlink_system_t gcs_mavlink_system;

#if USART1_ENABLE==1
	extern UART_HandleTypeDef huart1;
#endif

#if USART2_ENABLE==1
	extern UART_HandleTypeDef huart2;
#endif

#if USART3_ENABLE==1
	extern UART_HandleTypeDef huart3;
#endif

extern TIM_HandleTypeDef htim1;

extern IWDG_HandleTypeDef hiwdg;

#endif
